package com.sa07.control;

import java.util.List;

import com.sa07.bean.TestItemBean;
import com.sa07.bean.TestSubItem;
import com.sa07.bean.TestType;
import com.sa07.ui.enums.TestResult;

/**
 * 测试项执行器
 * 
 * @author Long.shangbo
 *
 * 2014-2-25 上午1:08:37
 */
public class TestItemExecutor {
	
	
	/**
	 * 测试执行方法
	 * @param testItem
	 * @return
	 */
	public TestResult executeTest(TestItemBean testItem){
		int testType = testItem.getTestItemType();
		List<TestSubItem> subItems = testItem.getTestSubItems();
		
		if(subItems == null || subItems.isEmpty()) return TestResult.FAILED;
		
		ITest subTest = null;
		TestResult res = TestResult.SUCCESS;
		
		for(TestSubItem subItem : subItems){
			if(TestType.LOW_MACHINE_TEST.getTestCode() == testType){
				subTest = new RemoteTest();
			}else if(TestType.CUSTOM_DIALOG_TEST.getTestCode() == testType){
				subTest = new CustomTest();
			}else{
				//暂时先不做本机测试
			}
			
			if(subTest != null){
				res = subTest.test(subItem);
				
				//如果有一项测试失败，则不再测试其他项
				if(res == TestResult.FAILED){
					break;
				}
			}
		}
		
		return res;
	}
}
